package com.duyinone.demo.mvp.base;

import android.util.Log;

import com.duyinone.demo.mvp.mvp.IModel;
import com.duyinone.demo.mvp.mvp.IPresenter;
import com.duyinone.demo.mvp.mvp.IView;

/**
 * Created by 杜晓鸣 on 2021/2/9
 * Creation time: 2021/2/9 23:22
 * Class Note:
 */
public class BasePresenter<V extends IView,M extends IModel> implements IPresenter {

    protected V mView;
    protected M mModel;

    /**
     * 如果当前页面不需要操作数据,只需要 View 层,则使用此构造函数
     *
     * @param view 1
     */
    public BasePresenter(V view){
        this.mView = view;
        onStart();
    }

    /**
     * 如果当前页面同时需要 Model 层和 View 层,则使用此构造函数(默认)
     *
     * @param model 1
     * @param view 1
     */
    public BasePresenter(V view,M model){
        this.mView = view;
        this.mModel = model;
        onStart();
    }

    public BasePresenter() {

    }

    @Override
    public void onStart() {
        if (mView != null && mModel != null){
            mModel.onDestroy();
            Log.e("TAG", "onStart: " + "Not null" );
        }

        Log.e("TAG", "onStart: " + "不需要M层的函数");
    }

    @Override
    public void onDestroy() {
        //在不需要M层时onDestroy默认释放V层和M层绑定，反之先释放M层的资源
        if (mModel != null) {
            mModel.onDestroy();
        }
        this.mModel = null;
        this.mView = null;
    }
}
